<?php 
namespace app\common\service;

use app\common\upload\AliossDriver;
use app\common\upload\LocalDriver;
use app\common\upload\QnossDriver;
use app\common\upload\We7Driver;
use EasyAdmin\upload\driver\Txcos;
use EasyAdmin\upload\Uploadfile;

/**
 * 
 * 重写easyadmin的上传保存方法，主要用来处理返回url和微擎的匹配
 */
class UploadService extends Uploadfile
{
    /**
     * 微擎系统的上传配置
     */
    public function save(){
        $obj = new We7Driver();

        $save = $obj->setUploadConfig($this->uploadConfig)
            ->setUploadType($this->uploadType)
            ->setTableName($this->tableName)
            ->setFile($this->file)
            ->save();
        return $save;
    }
    /**
     * 保存文件本地系统 thinkphp的配置
     * 暂时不用，独立系统才用
     * @return array|void
     */
    public function save_think()
    { 
        $obj = null;
        if ($this->uploadType == 'local') {
            //重新了easyadmin的 save方法
            $obj = new LocalDriver();
        } elseif ($this->uploadType == 'alioss') {
            //如果路径返回不对，需要重写save方法
            $obj = new AliossDriver();
        } elseif ($this->uploadType == 'qnoss') {
            $obj = new QnossDriver();
        } elseif ($this->uploadType == 'txcos') {
            $obj = new Txcos();
        }
        $save = $obj->setUploadConfig($this->uploadConfig)
            ->setUploadType($this->uploadType)
            ->setTableName($this->tableName)
            ->setFile($this->file)
            ->save();
        return $save;
    }

}